package com.lushixiang.database;

import com.lushixiang.mybatis.entity.usercheckcode.UserCheckCodeEntity;
import com.lushixiang.mybatis.maps.UserCheckCodeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class UserCheckCodeDao{

    @Autowired
    UserCheckCodeMapper userCode;

    public boolean insert(UserCheckCodeEntity code) {
        try{
            userCode.insert(code);
        }catch (Exception e){
            log.info("插入验证码{}发生异常{}",code,e.toString());
            return false;
        }
        return true;
    }

    // 查询用户验证码
    public UserCheckCodeEntity selectByEmailAddr(String emailAddr) {
        UserCheckCodeEntity userCheckCodeEntity = null;
        try{
            return userCode.selectByEmailAddr(emailAddr);
        }catch (Exception e){
            log.info("查询邮件{}验证码,失败原因 {}",userCheckCodeEntity,e);
        }
        return null;
    }

    public boolean deleteByEmailAddr(String emailAddr) {
        try{
            return userCode.deleteByEmailAddr(emailAddr);
        }catch (Exception e){
            log.error("删除邮件{}验证码记录发生异常{}",emailAddr,e);
        }
        return false;
    }
}
